﻿import React, { Component} from 'react'
import PropTypes from 'prop-types';
import { connect } from 'react-redux'
import style from "./style.less"
//import ResizableBox from 'react-resizable-box';
import { bindActionCreators } from 'redux';
import * as actions from '../../actions/doc-node';
import * as types from '../../ActionTypes'
import $ from 'jquery';
import  ResizableBox from '../react-resizable-box';

class CurrentLight extends Component {
	constructor(props) {
		super(props);
	}
	onResize(){
		const {dispatch,currentNode,nodeTree} = this.props;
		dispatch.nodeTreeUpdateByPath({
			nodeTree:nodeTree,
			node:{
				path:currentNode.path,
				styles:{
					width:arguments[2].offsetWidth - currentNode.sizeFix.width,
					height:arguments[2].offsetHeight - currentNode.sizeFix.height
				}
			}
		});
		dispatch.currentHighLightUpdate({width:arguments[2].offsetWidth,height:arguments[2].offsetHeight});
	}
	render() {
		const {isShow,operationMode,data} = this.props;
		var stylesScale={top:data.top,left:data.left,position:"absolute"}
		var stylesSelect={width:data.width,height:data.height,top:data.top,left:data.left,position:"absolute"}
		switch(operationMode){
			case "scale":
				console.log("data.width:");
				console.log(data.width);
				return (
					<ResizableBox
					className={"current-light "+ operationMode}
					width={data.width}
					height={data.height}
					style={stylesScale}
					onResize={this.onResize.bind(this)}
						/>
				)
				break;
			case "select":
				return (
					<div className={"current-light "+ operationMode} style={stylesSelect}>
					</div>
				)
				break;
			default:
				return (
					<div className={"current-light "+ operationMode} style={stylesSelect}>
					</div>
				)
				break;
		}
	}
}

CurrentLight.defaultProps = {
	isShow:false
};

function mapStateToProps(state) {
	return {
		nodeTree:state.nodeTree,
		data:state.currentHighLight,
		operationMode:state.operationMode,
		currentNode:state.currentNode
	}
}

function mapDispatchToProps(dispatch) {
	return {
		dispatch: bindActionCreators(actions, dispatch)
	}
}

export default connect(
	mapStateToProps,
	mapDispatchToProps
)(CurrentLight)


